package com.danton.model;

import java.util.List;

import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;

@SuppressWarnings("serial")
public class BsAdminModel extends Model<BsAdminModel> {
	public static final BsAdminModel dao = new BsAdminModel();

	public List<BsAdminModel> findUserByRoleID(int roleID) {
		return super.find("select "
				+ "bar.admin_id as user_id, "
				+ "ba.nike_name "
				+ "from "
				+ "bs_admin ba join bs_admin_role bar on ba.id = bar.admin_id "
				+ "where "
				+ "bar.role_id=?", roleID);
	}
	public BsAdminModel findByUserName(String user_name) {
		return super.findFirst("select * from bs_admin where user_name=?", user_name);
	}

	public BsAdminModel findByUserNameAndPassword(String user_name, String password) {
		return super.findFirst("select * from bs_admin where user_name=? and password=?", user_name, password);
	}
	
	public Page<BsAdminModel> paginate(int pageNumber, int pageSize){
		return super.paginate(pageNumber, pageSize, "select *,id as user_id", "from bs_admin order by create_time desc");
	}
	
	public Page<BsAdminModel> paginateByKw(int pageNumber, int pageSize,String kw){
		String likeKw = "%"+kw+"%";
		return super.paginate(pageNumber, pageSize, "select *,id as user_id",
				"from bs_admin where id=? or user_name=? or nike_name like ?  order by create_time desc", kw, kw, likeKw);
	}
	/*or department like ?  , likeKw*/
}
